package flc.ast.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.stark.cast.screen.CastScreenManager;

import flc.ast.R;
import flc.ast.activity.ProPicActivity;
import flc.ast.activity.ProRecordActivity;
import flc.ast.activity.SearchDeviceActivity;
import flc.ast.activity.SelAudioActivity;
import flc.ast.activity.SelPicActivity;
import flc.ast.activity.SelVideoActivity;
import flc.ast.databinding.FragmentProBinding;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelFragment;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link ProFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class ProFragment extends BaseNoModelFragment<FragmentProBinding> {

    private CastScreenManager mCastScreenManager;

    @Override
    protected int onCreate() {
        return R.layout.fragment_pro;
    }

    @Override
    protected void initView() {
        mDataBinding.ivSearch.setOnClickListener(this);
        mDataBinding.tvDisConnect.setOnClickListener(this);
        mDataBinding.ivProVideo.setOnClickListener(this);
        mDataBinding.ivProPicture.setOnClickListener(this);
        mDataBinding.ivProAudio.setOnClickListener(this);
        mDataBinding.ivProRecord.setOnClickListener(this);

        mCastScreenManager = CastScreenManager.getInstance();
    }

    @Override
    protected void onClickCallback(View v) {
        int id = v.getId();
        if (id == R.id.ivSearch) {//搜索设备
            startActivity(SearchDeviceActivity.class);
        } else if (id == R.id.tvDisConnect) {//取消连接
            Content.IsConnect = false;
            mCastScreenManager.disConnect();
            Content.ConnectName = "";
            isConnect();
        } else if (id == R.id.ivProVideo) {//视频投屏
            if (!Content.IsConnect) {
                ToastUtils.showShort(R.string.please_conn_pro_device);
                return;
            }
            startActivity(SelVideoActivity.class);
        } else if (id == R.id.ivProAudio) {//音频投屏
            if (!Content.IsConnect) {
                ToastUtils.showShort(R.string.please_conn_pro_device);
                return;
            }
            startActivity(SelAudioActivity.class);
        } else if (id == R.id.ivProPicture) {//图片投屏
            if (!Content.IsConnect) {
                ToastUtils.showShort(R.string.please_conn_pro_device);
                return;
            }
            startActivity(SelPicActivity.class);
        } else if (id == R.id.ivProRecord) {//投屏记录
            startActivity(ProRecordActivity.class);
        }
    }

    @Override
    protected void initData() {
        mDataBinding.tvWifiName.setText(NetworkUtils.getSSID());
    }

    @Override
    public void onResume() {
        super.onResume();
        isConnect();
    }

    private void isConnect() {
        if (Content.IsConnect) {
            mDataBinding.tvDeviceName.setText(Content.ConnectName);
            mDataBinding.tvDisConnect.setVisibility(View.VISIBLE);
        } else {
            mDataBinding.tvDeviceName.setText(getString(R.string.not_conn));
            mDataBinding.tvDisConnect.setVisibility(View.GONE);
        }
    }
}